package com.suqiu.client;

import com.suqiu.config.RabbitConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

/**
 * @author 江南一点雨
 * @微信公众号 江南一点雨
 * @网站 http://www.itboyhub.com
 * @国际站 http://www.javaboy.org
 * @微信 a_java_boy
 * @GitHub https://github.com/lenve
 * @Gitee https://gitee.com/lenve
 */
@Slf4j
@RestController
public class RpcClientController {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public String send(String msg) {
        MessageProperties messageProperties = new MessageProperties();
        Message message = new Message(msg.getBytes(StandardCharsets.UTF_8), messageProperties);
        log.info("【发送的消息-社会信用代码】：" + msg);
        Object result = rabbitTemplate.convertSendAndReceive(RabbitConfig.RPC_EXCHANGE, RabbitConfig.RPC_QUEUE1, message);
        log.info("【同步消息返回结果-msgResult】：{}", result);
        return result.toString();
    }
}